﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Common;
using ManagerMachine.Converter;

namespace ManagerMachine
{
    public partial class ServerMachineGroup
    {
        void Login_Server_L_CreateTable(object[] param)
        {
            int UserID = 0;
            int TableID = 0;
            convert_data_login.ConvertReceive_L_CreateTable(ref UserID, ref TableID, param);
            int newport =  manager_process.StartNewTable(TableID);
            Thread.Sleep(700);
            SendMessage_L_CreatTable_OK(UserID, TableID, config.IP_TABLE_SERVER, newport);

        }
        void Login_Server_L_JoinTable(object[] param)
        {
            int UserID = 0;
            int TableID = 0;
            convert_data_login.ConvertReceive_L_JoinTable(ref UserID, ref TableID, param);
            int port = manager_process.GetPort(TableID);
            SendMessage_L_JoinTable_OK(UserID, TableID, config.IP_TABLE_SERVER, port);
        }

        void Login_Server_L_Remove_Table(object[] param)
        {
            int TableID = 0;
            convert_data_login.ConvertReceive_L_Remove_Table(ref TableID, param);
            if (manager_process.StopTable(TableID))
                Console.Write("Table ID = {0} Stoped Success!", TableID);
            else
                Console.WriteLine("Table isn't exist!");
            
        }
        void Login_Server_L_CreateRoom(object[] param)
        {
            int UserID = 0;
            int RoomID = 0;
            String RoomName = null;
            convert_data_login.ConvertReceive_L_CreateRoom(ref UserID, ref RoomID, ref RoomName, param);
            SendMessage_L_CreateRoom_OK(UserID, RoomID, RoomName);
        }
        void Login_Server_L_JoinRoom(object[] param)
        {
            int UserIDJoin = 0;
            int RoomID = 0;
            convert_data_login.ConvertReceive_L_JoinRoom(ref UserIDJoin, ref RoomID, param);
            SendMessage_L_JoinRoom_OK(UserIDJoin, RoomID);
        }
    }
}
